package com.woniu.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.woniu.been.entity.CourseCategories;
import com.woniu.been.entity.CourseChapters;
import com.woniu.been.entity.Courses;
import com.woniu.been.entity.Video;

@Mapper
public interface CourseChaptersMapper {

//    @Select("SELECT * FROM course_categories")
    List<Courses> getCapter(CourseCategories coursecategories);

    List<Courses> getCapterByID(Courses course);

    @Select("SELECT * FROM video WHERE course_id = #{courseId}")
    List<Video> getVideos(Video video);

    //    @Select("SELECT * FROM course_categories")
//    List<CourseCategories> selectCourse(CourseCategories courseCategories);

    /**
     * 根据课程ID获取章节列表
     * @param courseId 课程ID
     * @return 章节列表
     */
    @Select("SELECT cc.chapter_id, cc.chapter_name FROM course_chapters cc " +
            "JOIN course_chapters_relations ccr ON cc.chapter_id = ccr.chapter_id " +
            "WHERE ccr.course_id = #{courseId}")
    List<CourseChapters> findChaptersByCourseId(Integer courseId);

    /**
     * 根据章节ID获取章节名称
     * @param chapterId 章节ID
     * @return 章节名称
     */
    @Select("SELECT chapter_name FROM course_chapters WHERE chapter_id = #{chapterId}")
    String findChapterNameById(Integer chapterId);
    
    /**
     * 根据章节名称获取章节ID
     * @param chapterName 章节名称
     * @return 章节ID
     */
    @Select("SELECT chapter_id FROM course_chapters WHERE chapter_name = #{chapterName}")
    Integer findChapterIdByName(String chapterName);
    
    List<CourseChapters> findChaptersByCourseIds(Integer courseId);
    CourseChapters findChapterById(Integer chapterId);
    int insertChapter(CourseChapters chapter);
    int updateChapter(CourseChapters chapter);
    int deleteChapter(Integer chapterId);

    // 章节-课程关联
    int insertRelation(@Param("chapterId") Integer chapterId, @Param("courseId") Integer courseId);
    int deleteRelationByChapterId(Integer chapterId);
    
    /**
     * 根据课程小类ID获取章节列表（通过course_category_relations表关联）
     * @param categoryId 课程小类ID
     * @return 章节列表
     */
    List<CourseChapters> findChaptersBySubCategoryId(Integer categoryId);

    // 章节-课程小类关联
    int insertChapterCategoryRelation(@Param("chapterId") Integer chapterId, @Param("categoryId") Integer categoryId);
    int deleteChapterCategoryRelationByChapterId(Integer chapterId);

}
